<%--
  Created by IntelliJ IDEA.
  User: hp
  Date: 2019/1/11
  Time: 10:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>入库审核</title>
    <jsp:include page="${pageContext.request.contextPath}/common/tag.jsp"/>
</head>
    <script>
        $(function () {
            $("#rukutable").bootstrapTable({
                url : '${pageContext.request.contextPath}/audit/gettgshen',
                height : 400,
                pagination : true, //开启分页
                pageSize : 5, //每页显示的行数
                pageList:[2,4,8,16], //设置可供选择的页面数据条数
                pageNumber:1, //如果设置了分页，首页页码。
                sidePagination:'server',  //启用服务器端分页
                queryParams:function(params){
                    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        limit: params.limit,  //页面大小
                        offset: params.offset, //页码
                        danhao:$("#danhao").val()
                    };
                    return temp;
                },
                columns : [
                    {checkbox:true},
                    {field : 'danhao',title : '单据号',align : 'center'},
                    {field : 'astatic.asname',title : '审核状态',align : 'center',color:'red'},
                    {field : 'cgdate',title : '采购日期',align : 'center'},
                    {field : 'shuliang',title : '商品总数量',align : 'center'},
                    {field : 'yingshou',title : '总金额',align : 'center'},
                    {field : 'staff.yName',title : '经办人',align : 'center'},
                    {field : 'beizhu',title : '备注',align : 'center'},
                    {title : '操作',align:'center',formatter: function(value,row,index) {
                            return  "<button class='btn btn-danger' onclick='ruku("+index+")'>入库</button>"
                        }
                    }
                ]
            })
        });
    </script>
<body style="margin:20px 10px;overflow-y: hidden;">
    <div>
        <form class="form-inline" style="margin-top: 20px;text-align: right">
            <div class="form-group">
                <label for="danhao">订单号：</label>&nbsp;
                <input type="text" class="form-control" id="danhao" placeholder="请输入订单号" style="height: 40px;">
            </div>
            <button onclick="serch();" class="btn btn-primary btn-lg" type="button"><span class="glyphicon glyphicon-search">搜索</span></button>
        </form>
        <table id="rukutable"></table>
        <%--<table id="xiangqing"></table>--%>
    </div>
</body>
<script>
    function serch() {
        //返回表格的 Options。
        var opts = $("#rukutable").bootstrapTable("getOptions") ;
        //$("#shenhetable").bootstrapTable('refreshOptions',{pageNumber:1});
        var limit = opts.pageSize ;
        var offset = (opts.pageNumber-1) * limit;
        var danhao = $("#danhao").val() ;
        $.post("${pageContext.request.contextPath}/audit/gettgshen",{'danhao':danhao,'limit':limit,'offset':offset},function (data) {
            // var mydata = eval("("+data+")") ;
            //重新绑定表格数据
            $("#rukutable").bootstrapTable('load',data) ;
        })
    };
    /*入库单击事件*/
    function ruku(index) {
        $("#rukutable").bootstrapTable("uncheckAll");
        $("#rukutable").bootstrapTable("check",index);
        var rows = $("#rukutable").bootstrapTable('getSelections')[0];
        console.log(rows);
        swal({
            title: "您确定要审核这条信息吗",
            text: "审核后将无法恢复，请谨慎操作！",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "审核",
            closeOnConfirm: false
        },function () {
            $.post('${pageContext.request.contextPath}/audit/addkucun',{"danhao":rows.danhao},function (data) {
                console.log(data);
                if(data.row>0){
                    /*销毁*/
                    $('#rukutable').bootstrapTable('destroy');
                    /*从新绑定*/
                    $('#rukutable').bootstrapTable({
                        url : '',
                        height : 400,
                        columns : [
                            {checkbox:true},
                            {field : 'danhao',title : '单据号',align : 'center'},
                            {field : 'astatic.asname',title : '审核状态',align : 'center',color:'red'},
                            {field : 'cgdate',title : '采购日期',align : 'center'},
                            {field : 'shuliang',title : '商品总数量',align : 'center'},
                            {field : 'yingshou',title : '总金额',align : 'center'},
                            {field : 'staff.yName',title : '经办人',align : 'center'},
                            {field : 'beizhu',title : '备注',align : 'center'},
                            {title : '操作',align:'center',formatter: function(value,row,index) {
                                    return  "<button class='btn btn-danger' onclick='ruku("+index+")'>入库</button>"
                                }
                            }
                        ]
                    });
                    swal("提示信息", "入库成功!", "success");
                }
            })
        });
    }
</script>
</html>
